﻿var pageid;
//帐户注销
function accountlogout() {
    elayer.confirm('注销', '你确定要退出本网站吗?', function () {
        window.location.href = "/Account/LogOut";
    });
}

//ajax删除
function ajaxdelete(target) {
    var confirmid = elayer.confirm('删除', '你确认要删除吗？', function () {
        $.ajax({
            url: $(target).data('url'),
            type: 'post',
            error: function (e) {
                alert(e.responseText);
                elayer.alert('错误', '网络连接失败...');
                elayer.close(confirmid);
            },
            success: function (data) {
                elayer.close(confirmid);
                if (!data.status) {
                    elayer.alert('错误', data.errmsg);
                }
                    //操作成功
                else if (data.status) {
                    $(target).parents(".ajax-item").remove();
                    //删除成功后，回调方法
                    if ($(target).data('successcallback')) {
                        eval($(target).data('successcallback'))(data);
                    }
                }
            }
        });
    });
}
//ajax还原
function ajaxrecovery(target) {
    var confirmid = elayer.confirm('还原', '你确认要还原吗？', function () {
        $.ajax({
            url: $(target).data('url'),
            type: 'post',
            error: function (e) {
                alert(e.responseText);
                elayer.alert('错误', '网络连接失败...');
                elayer.close(confirmid);
            },
            success: function (data) {
                elayer.close(confirmid);
                if (!data.status) {
                    elayer.alert('错误', data.errmsg);
                }
                    //操作成功
                else if (data.status) {
                    $(target).parents(".ajax-item").remove();
                    //删除成功后，回调方法
                    if ($(target).data('successcallback')) {
                        eval($(target).data('successcallback'))(data);
                    }
                }
            }
        });
    });
}
//ajax开启&关闭考试\投票\调研
function ajaxopenexam(target) {
    var text = $(target).find(".span-text").text();
    var confirmid = elayer.confirm('确认', "你确认要" + text + "吗？", function () {
        $.ajax({
            url: $(target).data('url'),
            type: 'post',
            error: function (e) {
                alert(e.responseText);
                elayer.alert('错误', '网络连接失败...');
                elayer.close(confirmid);
            },
            success: function (data) {
                elayer.close(confirmid);
                if (!data.status) {
                    elayer.alert('错误', data.errmsg);
                }
                //操作成功
                else if (data.status) {
                    var isOpen = data.data.IsOpen;
                    if (isOpen)
                    {
                        $(target).find(".fa").removeClass("fa-check").addClass("fa-remove");
                        $(target).find(".span-text").text("关闭");
                    } else {
                        $(target).find(".fa").removeClass("fa-remove").addClass("fa-check");
                        $(target).find(".span-text").text("开启");
                    }
                    elayer.alert('提示', data.errmsg);
                }
            }
        });
    });
}
//ajax 请求
function ajaxrequest(target) {
    var lid = elayer.loading();
    $.ajax({
        url: $(target).data('url'),
        type: 'post',
        error: function () {
            elayer.alert('错误', '网络连接失败...');
        },
        success: function (data) {
            elayer.close(lid);
            if (!data.status) {
                elayer.alert('错误', data.errmsg);
            }
                //操作成功
            else if (data.status) {
                elayer.alert('提示', data.data, function () {
                    elayer.close();
                    //请求成功后，回调方法
                    if ($(target).data('successcallback')) {
                        eval($(target).data('successcallback'))(data);
                    }
                });
            }
        }
    });
}

function ajaxLoadingList(target) {
    var loadingid = elayer.loading();
    var jsonparam = {};
    if ($('#ui-pager').data('json')) {
        jsonparam = $('#ui-pager').data('json');
    }
    var newurl = $('#ui-pager').data('url');
    if (newurl == undefined || typeof (newurl) === undefined) {
        newurl = window.location.href;
    }
    $.each(jsonparam, function (name, value) {
        newurl += newurl.indexOf("?") == -1 ? "?" : "&";
        newurl += name + "=" + value;
    });
    newurl += ((newurl.indexOf("?") == -1 ? "?" : "&") + "pageindex=" + $('#skipPage').val());
    $.ajax({
        type: 'post',
        url: newurl,
        data: $('form').serialize(),
        error: function () {
            //Ajax提交失败..
            elayer.alert("提示", "服务器没有返回数据,请重试..");
            elayer.close(loadingid);
        },
        success: function (html) {
            $('#ui-pager').empty();
            $('#ui-pager').append(html);
            elayer.close(loadingid);
        }
    });
}

//分页跳转
function skipPage() {
    var loadingid = elayer.loading();
    var jsonparam = {};
    if ($('#ui-pager').data('json')) {
        jsonparam = $('#ui-pager').data('json');
    }
    var newurl = $('#ui-pager').data('url');

    if (newurl == undefined || typeof (newurl) === undefined) {
        newurl = window.location.href;
    }
    $.each(jsonparam, function (name, value) {
        newurl += newurl.indexOf("?") == -1 ? "?" : "&";
        newurl += name + "=" + value;
    });
    newurl += ((newurl.indexOf("?") == -1 ? "?" : "&") + "pageindex=" + $('#skipPage').val());
    var order = $("input[name='order']").val();
    var by = $("input[name='by']").val();
    $.ajax({
        type: 'get',
        url: newurl,
        data: $('form').serialize(),
        error: function () {
            //Ajax提交失败..
            elayer.alert("提示", "服务器没有返回数据,请重试..");
            elayer.close(loadingid);

        },
        success: function (html) {
            elayer.close(loadingid);
            $('#ui-pager').empty();
            $('#ui-pager').append(html);
            if (order != undefined) {
                var th = $("td[data-sort='" + order + "']");
                th.removeClass("sorting");
                th.addClass("sorting_" + by);
                //th.css("background-color", "#EAEAEA");
            }
            sortInit();
        }
    });
}

//排序
function sortInit() {
    $("table .sorting,table .sorting_asc,table .sorting_desc").click(function () {
        var form = $(".right-panel").find("form");
        var order = "", by = "";
        if ($(this).attr("data-sort") != undefined) {
            order = $(this).attr("data-sort");
            if ($(this).hasClass("sorting") || $(this).hasClass("sorting_desc"))
                by = "asc";
            else if ($(this).hasClass("sorting_asc"))
                by = "desc";
            //var href = location.href;
            //if (href.indexOf("?") == -1)
            //    href += "?order=" + order + "&by=" + by;
            //else
            //    href += "&order=" + order + "&by=" + by;
            //保存信息
            if (form.find("input[name='order']").length == 0)
                form.append('<input type="hidden" name="order" value="" />');
            if (form.find("input[name='by']").length == 0)
                form.append('<input type="hidden" name="by" value="" />');

            //form = $(this).parents(".dt-pages:first").find("form");
            form.find("input[name='order']").val(order);
            form.find("input[name='by']").val(by);

            skipPage();
        }
    });
}

//ajax提交
var submitlock = false;
function ajaxSubmit(target, conofirm, confirmtext) {
    if (submitlock)
        return;

    var validate = $(target).parents('form').validationEngine("validate");
    if (validate) {
        submitlock = true;
        if (confirm) {
            var confirmid = elayer.confirm('确认', (confirmtext || '你确认要保存吗？'), function () {
                ajaxSubmitForm(target, confirmid);
            }, function () {
                elayer.close(confirmid);
                submitlock = false;
            }, function () {
                submitlock = false;
            });
        } else {
            ajaxSubmitForm(target);
        }
    }
}

function ajaxSubmitForm(target, confirmid) {
    if (confirmid) {
        elayer.close(confirmid);
    }
    var loadingid = elayer.loading();

    var self = $(target);
    var form = $(target).parents('form');
    var url = self.data('url');

    if (url == undefined || typeof (url) === undefined) {
        var actionurl = form.attr("action");
        if (actionurl == "") url = location.href;
        else url = actionurl;
    }
    $.ajax({
        type: 'POST',
        url: url,
        data: form.serialize(),
        success: function (data) {
            submitlock = false;
            //判断是否有ajax结果处理方法
            if (self.data('ajaxcallback')) {
                eval(self.data('ajaxcallback'))(data);
            }
                //操作失败
            else if (!data.status) {
                //如有验证码，刷新 验证码
                if (self.find("#img-verifycode").length > 0) {
                    $("#img-verifycode").trigger('click');
                }
                //失败回调方法
                if (self.data('failure')) {
                    eval(self.data('failure'))(data);
                } else {
                    elayer.alert('错误 ', data.errmsg);
                }
            }
                //操作成功
            else if (data.status) {
                //成功提示文本
                if (self.data('successmsg')) {
                    elayer.alert('提示', self.data('successmsg'));
                }
                    //成功跳转
                else if (self.data('successurl')) {
                    submitlock = true;
                    window.location.href = self.data('successurl');
                }
                    //成功回调方法
                else if (self.data('successcallback')) {
                    eval(self.data('successcallback'))(data);
                } else {
                    if (data.data) elayer.alert('提示', data.data);
                    else elayer.alert('提示', '保存成功.');
                }
            }

            elayer.close(loadingid);
        },
        error: function (e) {
            elayer.alert('错误 ', e.responseText);
        }
    });
}

//弹框页面
var dialogTarget;
function openTargetDialog(taget, w, h) {
    dialogTarget = $(taget);
    if (!w) w = 880;
    if (!h) h = 540;
    pageid = elayer.page(dialogTarget.attr("title"), '<iframe width="' + w + '" align="center" height="' + h + '" style="margin:0 20px ;" id="win" name="win" frameborder="0" src="' + $(taget).data('url') + '"></iframe>');
}

function openPreview(taget) {
    dialogTarget = $(taget);
    pageid = elayer.mobilepage('<iframe width="375" align="center" height="667" style="border:solid 1px #999;margin-top:60px;background-color:#fff;" id="win" name="win" frameborder="0" src="' + $(taget).data('url') + '"></iframe>');
}

function exportList(target) {
    var loadingid = elayer.loading();
    var jsonparam = {};
    if ($('#ui-pager').data('json')) {
        jsonparam = $('#ui-pager').data('json');
    }
    var newurl = $(target).data('url');

    if (newurl == undefined || typeof (newurl) === undefined) {
        newurl = window.location.href;
    }
    $.each(jsonparam, function (name, value) {
        newurl += newurl.indexOf("?") == -1 ? "?" : "&";
        newurl += name + "=" + value;
    });
    newurl += ((newurl.indexOf("?") == -1 ? "?" : "&") + $('form').serialize());
    var order = $("input[name='order']").val();
    var by = $("input[name='by']").val();

    window.location.href = newurl;
    elayer.close(loadingid);
}

function saveDialogForm(target, parentid, url) {
    saveDialogForm(target, parentid, url, false);
}
function saveDialogForm(target, parentid, url, manualClose) {
    var validate = $(target).parents('form.formvalidator').validationEngine("validate");
    if (validate) {
        $.ajax({
            url: url,
            data: $(target).parents('form').serialize(),
            type: 'post',
            error: function (e) {
                elayer.alert(e.responseText);
                elayer.alert('错误', '网络连接失败...');
            },
            success: function (data) {
                if (!data.status) {
                    elayer.alert('错误', data.errmsg);
                }
                    //操作成功
                else if (data.status) {
                    if (data.data) {
                        elayer.alert('提示', data.data);
                    }
                    if (!manualClose) {
                        window.parent.callbackCloseDialog(parentid);
                    }
                }
            }
        });
    }
}

function callbackCloseDialog(parentid) {
    elayer.close(pageid);
    $('button[type=submit]').trigger('click');
}
function closeDialog(target) {
    elayer.close(pageid);
}

function newguid() {
    var s = [];
    var hexDigits = "0123456789abcdefghijklmnopqrstuvwxyz";
    for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
    s[8] = s[13] = s[18] = s[23] = "-";

    return s.join("");
}
function DeleteOptionImg(target) {
    var self = $(target);
    $(self.data("value")).val("");
    $(self.data("img")).attr("src", "");
    self.hide();
}
function addoption(target) {
    var option = $('#divaddoption')[0].innerHTML;
    var rt = option.replace(/\[_GUID_\]/g, newguid()).replace(/\[_GUID2_\]/g, newguid());
    $(target).parents('.option-list').append(rt);
    initUploadImage($(target).parents('.col-xs-10'));
}
function removeoption(target) {
    $(target).parents('.option-item').remove();
}
function addchoicequestion() {
    var question = $('#divchoicequestion')[0].innerHTML;
    var rt = question.replace(/\[_GUID_\]/g, newguid()).replace(/\[_GUID2_\]/g, newguid());
    $('.question-list').append(rt);
    var uploadList = $(".question-list .question-item:last .option-list .option-item");
    $.each(uploadList, function (index, dom) {
        initUploadImage(dom);
    });
    initUploadImage();
}
function removequestion(target) {
    var confirmid = elayer.confirm('删除', '你确认要删除吗？', function () {
        elayer.close(confirmid);
        $(target).parents('.question-item').remove();
    });
}
function addopenquestion() {
    var question = $('#divopenquestion')[0].innerHTML;
    var rt = question.replace(/\[_GUID_\]/g, newguid()).replace(/\[_GUID2_\]/g, newguid());
    $('.question-list').append(rt);
}

function saveexam(target) {
    if (submitlock)
        return;

    submitlock = true;
    var loadingid = elayer.loading();
    $('input,select').removeClass('require');
    var questions = $('form .question-list .question-item');
    var list = [];
    var validate = $('form.formvalidator').validationEngine("validate");
    if (validate) {
        var vq = true;
        $.each(questions, function (i, d) {
            var qitem = $(d);
            var q = {};
            q.id = qitem.data('id');
            q.sn = qitem.data('sn');
            q.questiontype = qitem.find('input[name*=questiontype]:checked').val();
            q.questionname = qitem.find('input[name=questionname]').val();
            q.memo = qitem.find('input[name=memo]').val();
            if (qitem.find('input[name=score]').length > 0) {
                var s = parseInt(qitem.find('input[name=score]').val());
                q.score = isNaN(s) ? 0 : s;
            } else {
                q.score = 0;
            }
            if (qitem.find('input[name=sort]').length > 0) {
                var s = parseInt(qitem.find('input[name=sort]').val());
                q.sort = isNaN(s) ? 0 : s;
            } else {
                q.sort = 0;
            }
            q.isrequired = qitem.find('input[name*=isrequired]').is(':checked');

            if ($.trim(q.questionname).length == 0) {
                vq = false;
                $(qitem.find('input[name=questionname]')).eq(0).focus().addClass('require');
                elayer.close(loadingid);
                elayer.alert('提示', '标题不能为空！');
                submitlock = false;
                return false;
            }

            if (vq) {
                q.options = [];
                var vo = true;
                $.each(qitem.find('.option-item'), function (j, p) {
                    var oitem = $(p);
                    var o = {};
                    o.id = oitem.data('id');
                    o.sn = oitem.data('sn');
                    o.optionname = oitem.find('input[name=optionname]').val();
                    o.imgurl = oitem.find('input[name=imgurl]').val();
                    o.isanswer = oitem.find('input[name=isanswer]').is(':checked');
                    o.isallowinput = oitem.find('input[name=isallowinput]').is(':checked');

                    if ($.trim(o.optionname).length == 0 && $.trim(o.imageurl).length == 0) {
                        $(oitem.find('input[name=optionname]')).eq(0).focus().addClass('require');
                        elayer.close(loadingid);
                        elayer.alert('提示', '选项内容不能都为空！');
                        submitlock = false;
                        vo = false;
                        vq = false;
                        return false;
                    }

                    q.options.push(o);
                    return true;
                });

                if (!vo) {
                    submitlock = false;
                    return false;
                }

                list.push(q);
            }

            return true;
        });

        if (vq) {
            var et = "";
            if ($('#examtype').length > 0) {
                et = $("#examtype").val();
            } else {
                et = $("input[name=examtype]:checked").val();
            }
            $.ajax({
                type: 'post',
                url: '/ExpressLane/SaveExam/',
                data: {
                    id: $('#id').val(),
                    meetingid: $('#meetingid').val(),
                    sn: $("#sn").val(),
                    examtype: et,
                    examname: $('#examname').val(),
                    isshowtitle: $("input[name='isshowtitle']:checked").val(),
                    displaymode: $("input[name='displaymode']:checked").val(),
                    joinnumber: $("input[name='joinnumber']:checked").val(),
                    isanonymous: $("input[name='isanonymous']:checked").val(),
                    memo: $("textarea[name='memo']").val(),
                    starttime: $('#starttime').val(),
                    endtime: $('#endtime').val(),
                    questions: JSON.stringify(list)
                },
                success: function (data) {
                    elayer.close(loadingid);
                    if (data.status) {
                        if ($(target).data('successcallback')) {
                            eval($(target).data('successcallback'))(data);
                        } else {
                            elayer.alert('提示', '保存成功！');
                            location.href = $(target).data('successurl') + '?sn=' + data.data.sn;
                        }
                    } else {
                        submitlock = false;
                        elayer.alert("提示", data.errmsg);
                    }
                },
                error: function (e) {
                    elayer.alert("提示", e.responseText);
                }
            });
        }
    } else {
        submitlock = false;
        elayer.close(loadingid);
    }

}
//会议资料
function addMeetingData() {
    var meetingData = $('#divMeetingData')[0].innerHTML;
    var rt = meetingData.replace(/\[_GUID_\]/g, newguid()).replace(/\[_GUID2_\]/g, newguid());
    $('.question-list').append(rt);
    initUploadAttachment($('.question-list .data-box:last'));
}
function removeDataBox(target) {
    var confirmid = elayer.confirm("提示", '您确定要删除该资料吗？', function () {
        var id = $(target).parents(".data-box").find("#id").val();
        if (id != undefined) {
            $(target).parents(".data-box").find("#isdeleted").val("true");
            $(target).parents('.data-box').hide();
        }
        else {
            $(target).parents('.data-box').remove();
        }
        elayer.close(confirmid);
    }, function () {
        elayer.close(confirmid);
    });

}
function SaveMeetingData() {
    if (submitlock)
        return;
    submitlock = true;
    var loadingid = elayer.loading();
    var meetingDatas = $(".question-list .data-box");
    var list = [];
    var vq = true;
    $.each(meetingDatas, function (i, d) {
        var dataItem = $(d);
        var id = dataItem.find('input[name=id]').val();
        var isdeleted = dataItem.find('input[name=isdeleted]').val();
        var filetype = dataItem.find('input[name*=filetype]:checked').val();
        var name = dataItem.find('input[name=name]').val();
        var description = dataItem.find('input[name=description]').val();
        var jumpaddress = dataItem.find('input[name=jumpaddress]').val();
        var attachmenturl = dataItem.find('input[name*=attachmenturl]').val();
        if (name == "") {
            vq = false;
            submitlock = false;
            elayer.close(loadingid);
            elayer.alert('提示', "资料名称为必填！");
            return false;
        }
        list.push({ id: id, isdeleted: isdeleted, filetype: filetype, name: name, description: description, jumpaddress: jumpaddress, attachmenturl: attachmenturl });
    });

    if (vq) {
        $.ajax({
            type: 'post',
            url: '/Meeting/MeetingData/',
            data: {
                meetingid: $('#meetingid').val(),
                hasdata: $("#hasdata").val(),
                datas: JSON.stringify(list)
            },
            success: function (data) {
                elayer.close(loadingid);
                submitlock = false;
                if (data.status) {
                    elayer.alert('提示', data.data);
                } else {
                    elayer.alert("提示", data.errmsg);
                }
            },
            error: function (e) {
                elayer.alert(e.responseText);
            }
        });
    }
}


// 开启/关闭会议功能
function OpenCloseMeetingConfig(target, action, key, optionname) {
    var form = $(target).parents('form');
    var t = form.validationEngine("validate");
    if (t) {
        var v = $(target).data('value');
        var st = "关闭", sf = "开启";
        if (v == true || v == "true") {
            st = "开启";
            sf = "关闭";
        }
        var kv = $('#' + key).val();
        $('#' + key).val(v);
        var confirmid = elayer.confirm(st + '会议功能', '你确定' + st + ' [' + optionname + '] 功能吗？', function () {
            $.ajax({
                url: '/admin/meeting/' + action,
                type: 'post',
                data: form.serialize(),
                error: function (e) {
                    alert(e.responseText);
                    elayer.alert('错误', '网络连接失败...');
                    elayer.close(confirmid);
                },
                success: function (data) {
                    elayer.close(confirmid);
                    if (!data.status) {
                        elayer.alert('错误', data.errmsg);
                    }
                        //操作成功
                    else if (data.status) {

                        $(target).data('value', kv);
                        $(target).val(sf + '功能');

                        //删除成功后，回调方法
                        if ($(target).data('successcallback')) {
                            eval($(target).data('successcallback'))(data);
                        }
                    }
                }
            });
        });
    }
}

//发布会议
function releaseMeeting(examData) {
    if (examData && examData.status) {
        $('#meetingid').val(examData.data.meetingid);
    }
    var confirmid = elayer.confirm('发布会议', '你确认要发布会议吗？', function () {
        $.ajax({
            url: '/admin/meeting/releasemeeting',
            type: 'post',
            data: { meetingid: $('#meetingid').val() },
            error: function (e) {
                alert(e.responseText);
                elayer.alert('错误', '网络连接失败...');
                elayer.close(confirmid);
            },
            success: function (data) {
                elayer.close(confirmid);
                if (!data.status) {
                    elayer.alert('错误', data.errmsg);
                }
                    //操作成功
                else if (data.status) {
                    window.location.href = "/admin/Meeting/Released?meetingId=" + $('#meetingid').val();
                }
            }
        });
    });
}

function redirect(url) {
    window.location.href = url;
}

//处理K账号(只能输入字母数字和.)//
function checkUserIds(target) {
    $('#usercount').html('');
    var obj = $(target);
    var ids = generateUserIds(obj.val());
    if (ids.length > 0) {
        var num = ids.split(',').length;
        $('#usercount').html("共" + num + "个用户");
    }
    obj.val(ids);
}
function generateUserIds(ids) {
    ids = ids.toUpperCase() + ",";
    ids = ids.replace(/[^A-Za-z0-9\.]+/g, ',');
    var arrMobs = ids.split(",");
    ids = arrMobs.sort().toString() + ",";
    ids = ids.replace(/(\b[A-Za-z0-9\.]+,\b)\1+/g, "$1");

    return ids.replace(/^[^A-Za-z0-9\.]+|[^A-Za-z0-9\.]+$/g, "");
}

//处理手机号码(只能输入数字)//
function checkUserMobiles(target) {
    $('#usercount').html('');
    var obj = $(target);
    var ids = generateUserMobiles(obj.val());
    if (ids.length > 0) {
        var num = ids.split(',').length;
        $('#usercount').html("共" + num + "个用户");
    }
    obj.val(ids);
}
function generateUserMobiles(ids) {
    ids = ids.toUpperCase() + ",";
    ids = ids.replace(/[^0-9]+/g, ',');
    var arrMobs = ids.split(",");
    ids = arrMobs.sort().toString() + ",";
    ids = ids.replace(/(\b[0-9]+,\b)\1+/g, "$1");

    return ids.replace(/^[^0-9]+|[^0-9]+$/g, "");
}
//使用 ueditor 上传图片
function initUploadImage(container) {
    $('.uploadimage', container).each(function (i, item) {
        var self = $(this);
        self.parent().hide();
        var id = $(this).attr('id');
        if (id) {
            var editoruploadimage = UE.getEditor(id, {
                serverUrl: '/Areas/Admin/HTML/js/plugins/ueditor/net/controller.ashx',
                isShow: false,
                toolbars: [
                    ['insertimage']
                ]
            });

            var value = $(this).data('value');
            var img = $(this).data('img');
            var btn = $(this).data('btn');
            var callback = $(this).data('successcallback');

            editoruploadimage.ready(function () {
                self.find('.edui-editor').hide();
                self.parent().show();

                //上传成功
                editoruploadimage.addListener('beforeInsertImage', function (t, arg) {
                    if (arg.length > 0) {
                        editoruploadimage.setContent('');
                        //上传图片预览
                        if (img) {
                            $(img).attr('src', arg[0].src).show();
                        }
                        if (value) {
                            $(value).val(arg[0].src);
                        }
                    }
                    //上传完成，回调方法
                    if (callback) {
                        eval(callback)(arg);
                    }
                });

                //上传按妞事件            
                if (btn) {
                    $(btn).click(function () {
                        editoruploadimage.getDialog("insertimage").open();
                    });
                }
            });
        }
    });
}

function initUploadAttachment(container) {

    $('.uploadattachment', container).each(function (i, item) {
        var self = $(this);
        self.parent().hide();
        var id = $(this).attr('id');
        if (id) {
            var editoruploadattachment = UE.getEditor(id, {
                serverUrl: '/Areas/Admin/HTML/js/plugins/ueditor/net/controller.ashx',
                isShow: false,
                toolbars: [
                    ['attachment']
                ]
            });

            var value = $(this).data('value');
            var link = $(this).data('link');
            var btn = $(this).data('btn');
            var callback = $(this).data('successcallback');

            editoruploadattachment.ready(function () {
                self.find('.edui-editor').hide();
                self.parent().show();

                //上传成功
                editoruploadattachment.addListener('afterinsertfile', function (t, arg) {
                    if (arg.length > 0) {
                        editoruploadattachment.setContent('');
                        //生成下载链接<a>
                        if (link) {
                            $(link).attr('href', arg[0].url).show();
                        }
                        if (value) {
                            $(value).val(arg[0].url);
                        }
                    }
                    //上传完成，回调方法
                    if (callback) {
                        eval(callback)(arg);
                    }
                });

                //上传按妞事件            
                if (btn) {
                    $(btn).click(function () {
                        editoruploadattachment.getDialog("attachment").open();
                    });
                }
            });
        }
    });
}

function switchconfig(target) {
    var c = $(target).data('config');
    var v = $(target).data('cv');
    console.log(v);
    var st = "关闭";
    if (!v) {
        st = "开启";
    }
    var ov = $(target).data('ov');
    var confirmid = elayer.confirm(st + '会议功能', '你确定' + st + ' [' + ov + '] 功能吗？', function () {
        $.ajax({
            url: '/admin/meeting/switchmeetingconfig',
            type: 'post',
            data: { meetingid: $('#meetingid').val(), column: c, cv: (!v) },
            error: function (e) {
                alert(e.responseText);
                elayer.alert('错误', '网络连接失败...');
                elayer.close(confirmid);
            },
            success: function (data) {
                elayer.close(confirmid);
                if (!data.status) {
                    elayer.alert('错误', data.errmsg);
                }
                    //操作成功
                else if (data.status) {
                    var img = $($(target).siblings('a').find('img')[0]);
                    if (!v) {
                        $(target).data('cv', true);
                        $('#' + c).attr('checked', true);
                        $(img).attr('src', '/Areas/Admin/HTML/images/' + img.data('imgname') + '.png');
                        $(target).siblings('a').addClass('active');
                        $('.circle-large,.circle-text', target).addClass('active');
                    } else {
                        $(target).data('cv', false);
                        $('#' + c).attr('checked', false);
                        $(img).attr('src', '/Areas/Admin/HTML/images/' + img.data('imgname') + '-prey.png');
                        $(target).siblings('a').removeClass('active');
                        $('.circle-large,.circle-text', target).removeClass('active');
                    }
                }
            }
        });
    });
}

$(function () {
    sortInit();
    initUploadImage('body');
    initUploadAttachment('body');
    $(document).on('keyup', '.question-list input.require', function () {
        $(this).removeClass('require');
    });
});

//保存会议通知
function saveNotice(target) {
    var state = $(target).data("sendstate");
    $("#state").val(state);
    var templateForm = $("#templateForm").val();
    $("#jumpaddress").val($("#jumpaddress-text").val());
    if (templateForm == "#template-form-1") {
        var first = $(templateForm).find("#first").val();
        var keyword1 = $(templateForm).find("#keyword1").val();
        var keyword2 = $(templateForm).find("#keyword2").val();
        var keyword3 = $(templateForm).find("#keyword3").val();
        var remark = $(templateForm).find("#remark").val();
        if (first == "" || keyword1 == "" || keyword2 == "" || keyword3 == "" || remark == "") {
            elayer.alert('提示', "请完整填写模板字段！");
            return;
        }
        var json = [{ "key": "first", "value": first, "color": "#0000FF", "description": "" }, { "key": "keyword1", "value": keyword1, "color": "#FA0A0A", "description": "会议名称：" }, { "key": "keyword2", "value": keyword2, "color": "#173177", "description": "会议时间：" }, { "key": "keyword3", "value": keyword3, "color": "#173177", "description": "会议地点：" }, { "key": "remark", "value": remark, "color": "#888888", "description": "" }];
        $("#templatecontent").val(JSON.stringify(json));
    }
    else {
        var first = $(templateForm).find("#first").val();
        var keyword1 = $(templateForm).find("#keyword1").val();
        var keyword2 = $(templateForm).find("#keyword2").val();
        var remark = $(templateForm).find("#remark").val();
        if (first == "" || keyword1 == "" || keyword2 == "" || remark == "") {
            elayer.alert('提示', "请完整填写模板字段！");
            return;
        }
        var json = [{ "key": "first", "value": first, "color": "#0000FF", "description": "" }, { "key": "keyword1", "value": keyword1, "color": "#FA0A0A", "description": "会议名称：" }, { "key": "keyword2", "value": keyword2, "color": "#173177", "description": "通知类型：" }, { "key": "remark", "value": remark, "color": "#888888", "descripiton": "" }];
        $("#templatecontent").val(JSON.stringify(json));
    }
    var data = $("#notice-form").serialize();
    var url = "";
    if ($("#id").val() == undefined || $("#id").val() == "") {
        url = "/Admin/Meeting/NoticeCreate";
    }
    else {
        url = "/Admin/Meeting/NoticeEdit";
    }
    $.post(url, data, function (data) {
        if (data.status) {
            elayer.alert('提示', data.errmsg, function () {
                if (data.data.state == 0) {
                    window.location.href = "/Admin/Meeting/NoticeDraftList?meetingid=" + data.data.meetingId;
                }
                if (data.data.state == 1) {
                    window.location.href = "/Admin/Meeting/NoticeSentedList?meetingid=" + data.data.meetingId;
                }

                elayer.close();
            });
        }
        else {
            elayer.alert("提示", data.errmsg);
        }

    });
}

function NoAccess() {
    elayer.alert("提示", "您还未开通此功能，如需开通，请联系管理员！");
}
$.event.special.valuechange = {

    teardown: function (namespaces) {
        $(this).unbind('.valuechange');
    },

    handler: function (e) {
        $.event.special.valuechange.triggerChanged($(this));
    },

    add: function (obj) {
        $(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)
    },

    triggerChanged: function (element) {
        var current = element[0].contentEditable === 'true' ? element.html() : element.val()
          , previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous')
        if (current !== previous) {
            element.trigger('valuechange', [element.data('previous')])
            element.data('previous', current)
        }
    }
}

function IsURL(str_url) {
    var re = /^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/;
    if (!re.test(str_url)) {
        return false;
    }
    return true;
}